package io.renren.system.oss.tool;

import cn.hutool.core.util.StrUtil;

/**
 * 根据文件拓展获取MIME类型
 */
public class MiMETools {
    public static String parseContentType(String fileNameExtension) {
        if (StrUtil.endWithIgnoreCase(fileNameExtension, ".bmp")) {
            return "image/bmp";
        }
        if (StrUtil.endWithIgnoreCase(fileNameExtension, ".gif")) {
            return "image/gif";
        }
        if (StrUtil.endWithIgnoreCase(fileNameExtension, ".jpeg") ||
                StrUtil.endWithIgnoreCase(fileNameExtension, ".jpg") ||
                StrUtil.endWithIgnoreCase(fileNameExtension, ".png")) {
            return "image/jpg";
        }
        if (StrUtil.endWithIgnoreCase(fileNameExtension, ".html")) {
            return "text/html";
        }
        if (StrUtil.endWithIgnoreCase(fileNameExtension, ".txt") ||
                StrUtil.endWithIgnoreCase(fileNameExtension, ".text")) {
            return "text/plain";
        }
        if (StrUtil.endWithIgnoreCase(fileNameExtension, ".vsd")) {
            return "application/vnd.visio";
        }
        if (StrUtil.endWithIgnoreCase(fileNameExtension, ".pptx") ||
                StrUtil.endWithIgnoreCase(fileNameExtension, ".ppt")) {
            return "application/vnd.ms-powerpoint";
        }
        if (StrUtil.endWithIgnoreCase(fileNameExtension, ".docx") ||
                StrUtil.endWithIgnoreCase(fileNameExtension, ".doc")) {
            return "application/msword";
        }
        if (StrUtil.endWithIgnoreCase(fileNameExtension, ".xml")) {
            return "text/xml";
        }
        if (StrUtil.endWithIgnoreCase(fileNameExtension, ".pdf")) {
            return "application/pdf";
        }
        // 默认最后传jpg
        return null;
    }
}
